package com.inet.test02;


import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * 客户端发送一条数据，接收服务端返回的消息并打印
 * 服务端：接收数据并打印，再给客户端反馈消息
 * 注意：只能单次使用
 *
 * @Author weijingchen
 * @Date 2025/6/26 14:45
 * @Version 1.0.0
 */
public class Client {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1", 10201);
        Scanner sc = new Scanner(System.in);
        OutputStream os = socket.getOutputStream();

        System.out.println("请输入数据：");
        String line = sc.nextLine();
        os.write(line.getBytes());
        //输出完毕
        socket.shutdownOutput();

        InputStream is = socket.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        BufferedReader br = new BufferedReader(isr);
        int b;
        while ((b = br.read()) != -1) {
            System.out.print((char) b);
        }


        os.close();
        socket.close();
    }
}
